package com.baizhi.tag;

import com.baizhi.util.StringUtil;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.util.Map;

public class MyTag extends SimpleTagSupport {
    private int curPageId;
    private String name;
    private String value;

    @Override
    public void doTag() throws IOException, JspException {
        HttpSession session = ((PageContext) this.getJspContext()).getSession();
        Map<Integer, Map<String, String[]>> allParamsMap = (Map<Integer, Map<String, String[]>>) session.getAttribute("all_params");
        if (allParamsMap != null) {
            Map<String, String[]> map = allParamsMap.get(curPageId);
            if(map!=null){
                String[] oldValues = map.get(name);
                if (StringUtil.contains(oldValues, value)) {
                    getJspBody().invoke(null);
                }
            }
        }
    }

    public int getCurPageId() {
        return curPageId;
    }

    public void setCurPageId(int curPageId) {
        this.curPageId = curPageId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
